home *** CD-ROM | disk | FTP | other *** search
- Path: tank.news.pipex.net!pipex!iol!usenet
- From: David Byrden <Goyra@iol.ie>
- Newsgroups: comp.lang.c++
- Subject: Re: Help: Can't extract fractional digits of DOUBLE
- Date: 27 Mar 1996 20:52:55 GMT
- Organization: Ireland On-Line
- Message-ID: <4jc9r7$hnf@nuacht.iol.ie>
- References: <4jc3cc$5nj@atlas.tncnet.com>
- NNTP-Posting-Host: dialup-079.dublin.iol.ie
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22KIT (Windows; I; 16bit)
-
- Simon Lee (Simon Lee) wrote:
- >
- >Hello everyone,
- >
- >I'm trying to take a double value and extract each digit from the value.
-
-
- Not so easy, I'm afraid. The numbers are stored, not in decimal, but in
- a pattern based on binary, so multiplying them by 10 completely changes
- their bit pattern and potentially introduces more nonzero bits at the
- least significant positions.
-
- If you think of the number as being in base 2, and multiply by TWO each
- time, extracting binary digits, you will eventually get all the fractional
- bits out. You could then convert to decimal as a second step. Fractional
- nonrepeating binary numbers do turn into fractional nonrepeating decimal
- numbers.
-
-
- David
-
-
-
-